package com.cloudptt.wp.ui.address.adapter;

import java.util.List;

import com.cloudptt.wp.R;
import com.mcptt.db.model.UserInfo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class VideoAdapter extends BaseAdapter {
	

	private Context context;
	private List<UserInfo> list = null;
		
	public VideoAdapter(Context context,List<UserInfo> list) {
		this.context = context;
		this.list = list;	
	}

	public void setData(List<UserInfo> list){
		this.list = list;
		notifyDataSetChanged();
	}
	
	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null ;

		if ( convertView == null ) {
			convertView = LayoutInflater.from(context).inflate(R.layout.user_item_track, null);
			holder = new ViewHolder();
			holder.name = (TextView) convertView.findViewById(R.id.tv_user_name);
			holder.userIcon = (ImageView) convertView.findViewById(R.id.iv_user_icon);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		final UserInfo userInfo = list.get(position);
		String name = userInfo.getName();
		String number = userInfo.getAddrId();

		holder.name.setText(name);
		holder.name.setSelected(true);
		
		if(UserInfo.UserType_User == userInfo.getType()){
			if(userInfo.getOnlineState() == 1){
				holder.userIcon.setImageResource(R.drawable.friends_online);
			}else{
				holder.userIcon.setImageResource(R.drawable.friends_offline);
			}
		}
		
		else if(UserInfo.UserType_Dac == userInfo.getType()){
			
			holder.userIcon.setImageResource(R.drawable.dac_icon);
			
			if(userInfo.getOnlineState() == 1){
				holder.userIcon.setImageResource(R.drawable.dac_online);
			}else{
				holder.userIcon.setImageResource(R.drawable.dac_offline);
			}
		}

		return convertView;
	}
	
	class ViewHolder {
		public TextView  name;
		public ImageView userIcon;
	}
}
